package com.sakiko.audiobook.order.config;

import com.sakiko.audiobook.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * projectName: com.sakiko.audiobook.order.config
 *
 * @author: sakiko
 * time: 2025/10/12 2:57
 * description: 关于取消订单发送延迟消息 交换机 队列 等的配置
 * 延迟消息的实现: 1、死信队列  2、延迟插件
 */
@Configuration
public class CancelOrderMqConfig {

    // 交换机
    @Bean
    public Exchange dealayExchange() {
        // 设置配置参数
        HashMap<String, Object> map = new HashMap<>();
        map.put("x-delayed-type", "direct");
        // 设置交换机
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER, "x-delayed-message", true, false, map);
    }

    // 队列
    @Bean
    public Queue dealyQueue() {
        // 设置队列
        return new Queue(MqConst.QUEUE_CANCEL_ORDER, true, false, false);
    }

    // 绑定关系
    @Bean
    public Binding dealyBinding() {
        // 完成绑定
        return BindingBuilder.bind(dealyQueue()).to(dealayExchange()).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
    }

}
